
var util = require('util.js');
const App = getApp()

//检测token时效性
function tokenTime() {
  var currentTime = util.formatTime(new Date)
  wx.setStorageSync('cacheTime', currentTime)
  var cacheTime = wx.getStorageSync('cacheTime');
  var cacheTime = (new Date(cacheTime)).getTime();
  var currentTime = (new Date(currentTime)).getTime();
  var time = parseInt(currentTime - cacheTime)
  //console.log(time)
  if (time > 518400000) {  //重新登录
    App.login()
  } else {  //重新缓存时间
    wx.setStorageSync('cacheTime', currentTime)
  }
}


//封装微信的request
/*function request(url,data={},method="GET"){
   wx.request({
     url:url,
     data:data,
     method:method,
     header:{
       'Content-Type':'application/json'
     },
     success:function(res){
       console.log("succ")
     },
     fail:function(res){
       console.log("err")
     }
   })
}*/

module.exports = {
  tokenTime
  
}
